unit uVisitar;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, FMTBcd, DB, SqlExpr, Buttons, Provider, DBClient,
  Mask, JvExMask, JvToolEdit, Grids, DBGrids, EDBFind, JvExStdCtrls,
  JvCombobox, JvDBSearchComboBox, DBCtrls, dxCore, dxButton, ExtCtrls,
  XPMenu, rpcompobase, rpvclreport;

type
  TfVisitar = class(TForm)
    sdsInteressado: TSQLDataSet;
    sdsInteressadoCOD_INTERESSADO: TIntegerField;
    sdsInteressadoNOME: TStringField;
    sdsInteressadoCPF: TStringField;
    sdsInteressadoRG: TStringField;
    DBGrid1: TDBGrid;
    dstVisita: TDataSource;
    cdsVisita: TClientDataSet;
    dspvisita: TDataSetProvider;
    sdsVisita: TSQLDataSet;
    dspInteressado: TDataSetProvider;
    cdsInteressado: TClientDataSet;
    DataSource1: TDataSource;
    cdsInteressadoCOD_INTERESSADO: TIntegerField;
    cdsInteressadoNOME: TStringField;
    cdsInteressadoCPF: TStringField;
    cdsInteressadoRG: TStringField;
    sdsInteressadoDATA_CADASTRO: TDateField;
    cdsInteressadoDATA_CADASTRO: TDateField;
    VCLReport1: TVCLReport;
    XPMenu1: TXPMenu;
    Panel1: TPanel;
    BitBtn5: TdxButton;
    BitBtn6: TdxButton;
    Panel2: TPanel;
    Label1: TLabel;
    cdInteressado: TJvDBSearchComboBox;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    DBEdit1: TDBEdit;
    DBEdit2: TDBEdit;
    BitBtn1: TSpeedButton;
    DateEdit: TJvDateEdit;
    cdsVisitaCOD_IMALU: TIntegerField;
    cdsVisitaCOD_IMOBILIARIA: TStringField;
    cdsVisitaNR: TStringField;
    cdsVisitaVISITA: TStringField;
    cdsVisitaCOD_INTERESSADO: TIntegerField;
    cdsVisitaDATAVISITA: TDateField;
    cdsVisitaRUA: TStringField;
    sdsVisitaCOD_IMALU: TIntegerField;
    sdsVisitaCOD_IMOBILIARIA: TStringField;
    sdsVisitaNR: TStringField;
    sdsVisitaVISITA: TStringField;
    sdsVisitaCOD_INTERESSADO: TIntegerField;
    sdsVisitaDATAVISITA: TDateField;
    sdsVisitaRUA: TStringField;
    procedure FormShow(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
    procedure BitBtn5Click(Sender: TObject);
    procedure BitBtn6Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  fVisitar: TfVisitar;

implementation

uses UDM, uInteressado;

{$R *.dfm}

procedure TfVisitar.FormShow(Sender: TObject);
begin
   if (not cdsInteressado.Active) then
      cdsInteressado.Open;

   if (not cdsVisita.Active) then
      cdsVisita.Open;

   DateEdit.Text := DateToStr(Now);
end;

procedure TfVisitar.BitBtn1Click(Sender: TObject);
begin
     if (dm.cds_interessado.Active) then
         dm.cds_interessado.Close;
     dm.cds_interessado.Params[0].AsInteger := cdsInteressadoCOD_INTERESSADO.AsInteger;
     dm.cds_interessado.Open;
     cdsInteressado.Close;
     fInteressado:=TfInteressado.Create(Application);
     try
       fInteressado.ShowModal;
     finally
       fInteressado.Free;
     end;
     cdsInteressado.open;     
end;

procedure TfVisitar.BitBtn5Click(Sender: TObject);
begin
  if (cdInteressado.Text = '') then
  begin
     MessageDlg('Escolha um Cliente..', mtWarning, [mbOK], 0);
     exit;
  end;

  if (DateEdit.Text = '  /  /    ') then
  begin
     MessageDlg('Preencha o campo Data da visita..', mtWarning, [mbOK], 0);
     exit;
  end;

  cdsVisita.First;
  while not cdsVisita.Eof do
  begin
      cdsVisita.Edit;
      cdsVisitaCOD_INTERESSADO.AsInteger := cdsInteressadoCOD_INTERESSADO.AsInteger;
      cdsVisitaVISITA.AsString := 'OK1'; 
      cdsVisitaDATAVISITA.Value := StrToDate(DateEdit.Text);
      cdsVisita.ApplyUpdates(0);
      cdsVisita.Next;
  end;
  VCLReport1.Filename := str_relatorio + 'visita.rep';
  VCLReport1.Report.Params.ParamByName('COD').Value := cdsInteressadoCOD_INTERESSADO.AsInteger;
  VCLReport1.Execute;
  Close;

end;

procedure TfVisitar.BitBtn6Click(Sender: TObject);
begin
  Close;
end;

end.
